package com.powernode.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.powernode.domain.Area;
import com.powernode.model.Result;
import com.powernode.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 全国地区业务控制层
 */
@Api(tags = "全国地区业务接口管理")
@RequestMapping("admin/area")
@RestController
public class AreaController {

    @Autowired
    private AreaService areaService;

    @ApiOperation("查询全国地区列表")
    @GetMapping("list")
    public Result<List<Area>> loadAllAreaList() {
        List<Area> list = areaService.list();
        return Result.success(list);
    }

//    admin/area/mall/listByPid?pid=0
    @ApiOperation("根据地区的父节点标识查询子节点集合")
    @GetMapping("mall/listByPid")
    public Result<List<Area>> loadAreaList(@RequestParam Long pid) {
        List<Area> list = areaService.list(new LambdaQueryWrapper<Area>()
                .eq(Area::getParentId, pid)
        );
        return Result.success(list);
    }
}
